/*
 * MIT License
 * 
 * Copyright (c) 2017 wen.gu <454727014@qq.com>
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

/*****************************************************************************
 * Name:tiny_event.h
 *
 * Purpose: event implementation
 *     
 * Version: 0.1
 *
 * Developer:
 *     wen.gu,2017-03-09
 *
 *
 *****************************************************************************/


#ifndef __TINY_EVENT_H__
#define __TINY_EVENT_H__

#include "general_type.h"

#ifdef __cplusplus
extern "C"{
#endif

/***************************************************************************
 *
 * macro declaration
 *
 ***************************************************************************/

/***************************************************************************
 *
 * data structure declaration
 *
 ***************************************************************************/

/** event data structure define */
typedef struct tiny_event_s 
{
	GS32 target; /**< the target of current event sent(@see tiny_looper_id) */
	GU32 reply_id; /**< only used for the case of post and wait response.
			        *   if reply_id != 0, then need send response event.
					*/
	GU32 what; /**< what is this event */
	GU32 ext;  /**< the extension value of event(for user) */
	void* data; /**< data for event information(for user) */
}tiny_event_t;




/***************************************************************************
 *
 * API declaration
 *
 ***************************************************************************/

/**
 *@brief  create a event instance
 *
 *@param  what     [in] what is this event
 *@param  target   [in] this event will send to who
 *@param  evt_size [in] the total size of current event(@see note)
 *
 *@return success: event instance handle, fail: NULL.
 *@see
 *@note for example:
 *     1. tiny_event_t* evt = tfEventCreate(1,2 sizeof(tiny_event_t))
 *     
 *     2. typedef struct temp_evnt_s
 *        {
 *			  tiny_evnt_t base;
 *			  int t1;
 *			  char t2;
 *        }temp_evnt_t
 *        
 *        tiny_event_t* evt = tfEventCreate(1,2 sizeof(temp_evnt_t))
 *
 */
G_API tiny_event_t* tfEventCreate(GU32 what, GS32 target, GU32 evt_size);

/**
 *@brief  destroy a event instance
 *
 *@param  evt [in] pointer to event instance.
 *
 *@return node.
 *@see
 *
 */
G_API void tfEventDestroy(tiny_event_t* evt);




#ifdef __cplusplus
}
#endif

#endif //end of __TINY_EVENT_H__
